import {defineStore} from 'pinia'

export const useAside= defineStore('main',{
    state:()=>({
        // 控制侧边栏收缩的变量
        isCollapse:true,
        // 面包屑数据
        currentMenu:null,
        // 侧边栏数据
        tabList:[
            {
                path:'/',
                name:'home',
                label:'首页',
                icon:'house',
                url:'Home/Home'
            },
        ]
    }),
    actions:{
        // 控制侧边栏收缩的方法
        updateIscollapse(){
            this.isCollapse=!this.isCollapse
        },
        // 更新面包屑数据
        selectMenu(val){
            // console.log(val);
            if(val.name == 'home'){
                this.currentMenu=null
            }else{
                this.currentMenu=val
                let result = this.tabList.findIndex(item => item.name === val.name)
                result == -1 ? this.tabList.push(val) : ''
        
            }       
        },
        // 关闭tag
        closeTag(val){
            let res = this.tabList.findIndex(item=> item.name === val.name)
            this.tabList.splice(res,1)
        }
    },
    persist: true,
})